<%@page contentType="text/html; charset=UTF-8" import="com.pub.database.*,java.util.*" %>
<% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); %>
<% response.setHeader("Cache.Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",0);%>
<jsp:useBean id="WebFunction" scope="request" class="com.pub.web.WebFunction" />
<jsp:useBean id="DataViewForm" scope="request" class="com.pub.database.DataViewForm"/>

<jsp:setProperty name="DataViewForm" property="submitMethod" value="POST"/>
<jsp:setProperty name="DataViewForm" property="pageRowCount" value="10"/>
<jsp:setProperty name="DataViewForm" property="nowPageNum"/>
<jsp:setProperty name="DataViewForm" property="dataViewAction"/>
<jsp:setProperty name="DataViewForm" property="filterCol"/>
<jsp:setProperty name="DataViewForm" property="filterValue"/>
<jsp:setProperty name="DataViewForm" property="dvOrderByFields"/>
<jsp:setProperty name="DataViewForm" property="dvOrderBySeq"/>

<% WebFunction.setPortal_to_session(request); //set session from portal
//System.out.println(session.getAttribute("u_id"));
if (session.getAttribute("u_id")==null) {
  try {
    request.getRequestDispatcher((new StringBuffer("login.jsp")).insert(0, "/").toString()).forward(request, response);
  } catch (Exception le) {
    le.printStackTrace();
  }
  return;
}

  response.setContentType("text/html;charset=BIG5");
  request.setCharacterEncoding("BIG5");
  String flow_code = session.getAttribute("flow_code").toString();
  String strDBAlias = (request.getParameter("db_alias")==null ?"" :request.getParameter("db_alias"));
  if(strDBAlias.equals("")){
    return;
  }
  QueryBean gqbnDAO = new QueryBean(strDBAlias,true,"utf-8","utf-8");

  DataView dataView=null;
  dataView = new DataView(gqbnDAO);


  String strFlowCode = request.getParameter("flow_code")==null ? "":request.getParameter("flow_code");
  String strLoginUser = session.getAttribute("u_id")==null ? "" :session.getAttribute("u_id").toString();


  StringBuffer stbCondition = new StringBuffer();
  StringBuffer stbPageActionURI = new StringBuffer();

  stbPageActionURI.append(request.getRequestURI());
  stbPageActionURI.append("?db_alias=");
  stbPageActionURI.append(strDBAlias==null ? "" : strDBAlias);
  stbPageActionURI.append("&flow_code=");
  stbPageActionURI.append(strFlowCode==null ? "" : strFlowCode);


  DataViewForm.setTablesList("wkf_jst_eng,floweng_setup,flow_code,pnl_employee,wkf_url");

  stbCondition.append("(flow_code.flow_code = wkf_jst_eng.flow_code (+))");
  stbCondition.append(" AND (flow_code.flow_code=wkf_url.flow_code)");
  stbCondition.append(" AND ( (floweng_setup.flow_code=wkf_jst_eng.flow_code )");
  stbCondition.append(" AND (floweng_setup.flow_no=wkf_jst_eng.flow_no))");
  stbCondition.append(" AND (pnl_employee.employee_no=wkf_jst_eng.s_empno)");
  stbCondition.append(" AND (wkf_jst_eng.jst_flag='N')");
  stbCondition.append(" AND (wkf_jst_eng.r_empno='");
  stbCondition.append(strLoginUser);
  stbCondition.append("')");


  if(strFlowCode!=null && !strFlowCode.equals("")){
	//拆解flow_code
    String[] strAryFlowCode=strFlowCode.split(",");
	//第1個flow_code
	stbCondition.append(" AND (wkf_jst_eng.flow_code ='");
	stbCondition.append(strAryFlowCode[0]);
	stbCondition.append("'");
	//多個flow_code
	if(strAryFlowCode.length>1){
	  for(int i=1;i<strAryFlowCode.length;i++){
		  stbCondition.append(" OR wkf_jst_eng.flow_code ='");
		  stbCondition.append(strAryFlowCode[i]);
		  stbCondition.append("'");
	  }
	}
	stbCondition.append(")");
  }

if(request.getParameter("flownum")!=null && !request.getParameter("flownum").trim().equals("")){
	stbCondition.append(" AND (wkf_jst_eng.flow_num='");
	stbCondition.append(request.getParameter("flownum"));
	stbCondition.append("')");
}
if(request.getParameter("sempno")!=null && !request.getParameter("sempno").trim().equals("")){
	stbCondition.append(" AND (wkf_jst_eng.s_empno='");
	stbCondition.append(request.getParameter("sempno"));
	stbCondition.append("')");
}



  DataViewForm.setSQLCondition(stbCondition.toString());
  DataViewForm.setOrderByFields("wkf_jst_eng.flow_num");
  DataViewForm.setOrderBySeq("asc");
  DataViewForm.setGroupBy(null);
  DataViewForm.setHaving(null);

  ArrayList<Hashtable<String,Object>> laltColRelation = new ArrayList<Hashtable<String,Object>>();
  Hashtable<String,Object> lhtColRelationDetail = new Hashtable<String,Object>();
  ArrayList<String> laltLinkParamList=new ArrayList<String>();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "URL_WKF");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,"WKF_URL.URL_WKF");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "HIDDEN");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='hidden' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"URL_WKF");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();


  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "SEQNO");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,"WKF_JST_ENG.SEQNO");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "HIDDEN");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='hidden' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"SEQNO");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FLOW_NUM");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,"WKF_JST_ENG.FLOW_NUM");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'流程單號'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "LINK");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML,"<a target='_blank' href=");
  lhtColRelationDetail.put(dataView.STR_LINK_URI,"URL_WKF");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE, "FLOW_NUM");
  laltLinkParamList.add("");
  laltLinkParamList.add("FLOW_NUM");
  laltLinkParamList.add("seqno=");
  laltLinkParamList.add("SEQNO");
  lhtColRelationDetail.put(dataView.STR_LINK_PARAM,laltLinkParamList);

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "REC_DATE_TIME");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,"TO_CHAR(WKF_JST_ENG.REC_DATE_TIME,'yyyy/mm/dd hh24:mi:ss')");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'送件時間'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT TYPE=\"TEXT\" readonly class='input_noborder' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE, "REC_DATE_TIME");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "EMPLOYEE_NAME_C");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,"PNL_EMPLOYEE.EMPLOYEE_NAME_C");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'送件人'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='text' readonly class='input_noborder' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"EMPLOYEE_NAME_C");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "FLOW_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL,"FLOWENG_SETUP.FLOW_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'流程站別'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='text' readonly class='input_noborder' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"FLOW_DESC");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();


  DataViewForm.setColRelationUseArrayList(laltColRelation);
  DataViewForm.setJumpPageButtonShow(false);
  DataViewForm.setPageBtnOnTop(false);
  DataViewForm.setPageBtnOnButtom(true);
  DataViewForm.setFilterShow(false);
  DataViewForm.setJumpPageShow(true);
  DataViewForm.setRowsInfoShow(true);
  DataViewForm.setRowPageShow(false);
  DataViewForm.setExcelShow(false);
  DataViewForm.setOrderEnable(false);
  DataViewForm.setShowHeaderWhenNoData(true);
  DataViewForm.setAddNewShow(false);

  DataViewForm.setTableHeaderHtml("class='td_head_grid' align='center' width='680px'");
  DataViewForm.setPageActionURI(stbPageActionURI.toString());
  String strResult="";
  try{
    strResult=dataView.getOutputDataView(DataViewForm);
  }
  catch(Exception e){
    e.printStackTrace();
  }
  finally{

    try{gqbnDAO.close();gqbnDAO=null;}catch(Exception e){e.printStackTrace();}
 }

%>
<html>
<head>
<title>待處理事項</title>
<LINK HREF="/PUBPAGE/general/workflow.css" REL="STYLESHEET" TYPE="TEXT/CSS"/>
<base target='_self'/>
</head>
<body>
  <h4>待處理事項</h4>
  <form action="<%=request.getRequestURI()%>" method="POST">
    <table>
      <tr>
        <th>流程單別</th>
        <td><input type="text" name="flow_code" size="10" class="input" value="<%=(request.getParameter("flow_code")!=null ? request.getParameter("flow_code") : "")%>" /></td>
        <th>流程單號</th>
        <td><input type="text" name="flownum" size="13" maxlength="13" class="input" /></td>
        <th>送件人</th>
        <td><input type="text" name="sempno" size="8" maxlength="8" class="input" /></td>
        <td><input type="submit"  value="查詢" /></td>
      </tr>
    </table>
	<input type="hidden" name="db_alias" value="<%=request.getParameter("db_alias")%>"/>
<%=flow_code%>
  </form>
<%=strResult==null ? "":strResult%>
</body>
</html>
